storBattery = new Vue({
	el: "#storBattery",
	data: {
		currentUser:'', // 当前用户信息
		parentObject:{},
		list:[], //本次检查记录
		elseDesc:'',
		initNetSafeDeviceInfoList:[],
		yesOrNo:[],
		toolCheckAddEditVisible:false,
	},
	components:{
		processlog, // 流程日志	
	},
	created: function() {
		let _this = this
		_this.currentUser = JSON.parse(localStorage.getItem("neiosUser"))
		_this.parentObject = JSON.parse(localStorage.getItem("neiosGoDetail")).obj
		// 获取码表
		let dictCodes = 'NET_SAFE_INFO,YES_OR_NO';
		let dict = mui.neiosCommon.queryDict(dictCodes, (data) => {
			if (data != '') {
				_this.initNetSafeDeviceInfoList = data.NET_SAFE_INFO;
				_this.yesOrNo = data.YES_OR_NO;
			}
		})
		_this.getList()
	},
	methods: {
		// 周期码表转换
		cycleUnitChange (data) {
			return mui.neiosCommon.dictTransform(this.yesOrNo,data)
		},
		//获取列表
		getList(){
			let _this = this
			//网络安全列表
			let param = {
				"workId": this.parentObject.workId
			}
			mui.neiosRequst.httpRequst('/app/regularWork/networkSafeDeviceCheck/getNetSafeDeviceCheckInfoList', param,
				(data) => {
					if (data.code == '0') {
						_this.list = data.data.networkSafeInfoList ? data.data.networkSafeInfoList : [],
						_this.elseDesc = data.data.elseDesc == null ? "" : data.data.elseDesc;
						if (data.data.networkSafeId == null || data.data.networkSafeId == "") {
							if (this.currentUser["stationNewCode"] != null && this.currentUser["stationNewCode"] != "") {
								let param = {
									"newStationCode": this.currentUser["stationNewCode"]
								}
								console.log(JSON.stringify(param))
								mui.neiosRequst.httpRequst('/app/regularWork/networkSafeDeviceCheck/getLastNetworkSafeInfoList', param,
									(data) => {
										if (data.code == '0') {
											let lastNetworkSafeInfoList = data.data;
											//存在历史记录
											if (lastNetworkSafeInfoList != null && lastNetworkSafeInfoList.length > 0) {
												//带出该场站上次审核完成提交的设备名称和间隔
												lastNetworkSafeInfoList.forEach(e => {
													let netSafeDeviceInfo = {
														networkSafeInfoId: '', // 网络安全防护设备检查明细主键
														networkSafeId: '', // 网络安全防护设备检查批次主键
														checkDate: this.getTime(new Date(), 'day'),
														checkStaffCodeName: this.currentUser["userName"], // 新增时测试人为当前登陆人
														checkStaffCode: this.currentUser["userId"],
														checkStaffName: this.currentUser["name"],
														deviceName: e.deviceName, //设备名称
														bay: e.bay, // 所属间隔
														isWarning: '0', // 默认不告警
														isAmbientNormal: '1', // 默认环境正常
														isHaveAbnormalDevice: '0', // 默认无不正常设备
														problemLog: '' // 问题记录
													}
													_this.list.push(netSafeDeviceInfo);
												});
											} else { //场站首次办理
												_this.initNetSafeDeviceInfoList.forEach(e => {
													let netSafeDeviceInfo = {
														networkSafeInfoId: '', // 网络安全防护设备检查明细主键
														networkSafeId: '', // 网络安全防护设备检查批次主键
														checkDate: _this.getTime(new Date(), 'day'),
														checkStaffCodeName: _this.currentUser["userName"], // 新增时测试人为当前登陆人
														checkStaffCode: _this.currentUser["userId"],
														checkStaffName: _this.currentUser["name"],
														deviceName: e.itemText, //设备名称
														bay: e.itemDesc, // 所属间隔
														isWarning: '0', // 默认不告警
														isAmbientNormal: '1', // 默认环境正常
														isHaveAbnormalDevice: '0', // 默认无不正常设备
														problemLog: '' // 问题记录
													}
													_this.list.push(netSafeDeviceInfo);
												});
											}
										} else {
											mui.toast("获取数据错误：" + data.msg);
										}
									},
									(data) => {
										mui.toast("查询历史检查记录失败");
			
									}
								);
							} else {
								mui.toast("用户场站信息为空，无法查询历史检查记录");
							}
						}
					} else {
						mui.toast("获取数据错误：" + data.msg);
					}
				},
				(data) => {
					mui.toast("获取数据错误：" + data.msg);
				}
			);
		},
		// 查看详情
		upToolCheckDialogFn (item) {
			this.toolCheckAddEditVisible = true
			this.formData = JSON.parse(JSON.stringify(item))
			this.formData.checkStaffCodeName = "[" + this.formData.checkStaffCode + "]" + this.formData.checkStaffName
			this.formData.checkDate = this.getTime(new Date(), 'day')
		},
		// 关闭
		closeToolCheckAddEdit () {
			this.toolCheckAddEditVisible = false
			this.formData = {
				deviceName:'',
				deviceCode:'',
				neiosCheckItemNoteList:[]
			}
			this.formData.checkStaffCodeName = ''
			this.formData.checkDate = ''
		},
		//获取时间
		getTime(myDate, type) {
			var realYear = myDate.getFullYear();
			var myMonth = myDate.getMonth() + 1;
			var realMonth = myMonth;
			var myDay = myDate.getDate();
			var realDay = myDay;
			var myHour = myDate.getHours();
			var realHours = myHour;
			var myMinute = myDate.getMinutes();
			var realMinute = myMinute;
			var mySecond = myDate.getSeconds();
			var realSecond = mySecond;
			if (myMonth < 10) {
				realMonth = "0" + myMonth;
			}
			if (myDay < 10) {
				realDay = "0" + myDay;
			}
			if (myMinute < 10) {
				realMinute = "0" + myMinute;
			}
			if (myHour < 10) {
				realHours = "0" + myHour;
			}
			if (mySecond < 10) {
				realSecond = "0" + mySecond;
			}
			var realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours + ':' + realMinute + ':' +
				realSecond;
			if (type == "sec") {
				realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours + ':' + realMinute + ':' + realSecond;
			} else if (type == "min") {
				realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours + ':' + realMinute;
			} else if (type == "hour") {
				realDate = realYear + '-' + realMonth + '-' + realDay + ' ' + realHours;
			} else if (type == "day") {
				realDate = realYear + '-' + realMonth + '-' + realDay;
			} else if (type == "month") {
				realDate = realYear + '-' + realMonth;
			} else if (type == "year") {
				realDate = realYear;
			}
			return realDate;
		},
		
		
		// 返回
		goBack () {
			mui.back()
		}
	}
});